#include "equal_resampler.h"
#include <iostream>
using namespace std;
bool equal_resampler::resample_problem(boosting_problem & prob, double * d_t, int & argc, char **& argv, boosting_problem & selected_prob) {
	// find positive
	int pn = 0;
	int nn = 0;
	for(int i = 0; i < prob.l; i++) {
		if(prob.y[i] == 1) {
			pn ++;
		} else if(d_t[i] > 0) {
			nn ++;
		}
	}

	cout << nn << "\t";

	int size;
	if(nn >= pn) {
		size = 2 * pn;
	} else {
		return false;
	}

	selected_prob.l = size;
	selected_prob.dim = prob.dim;
	selected_prob.y = new double[size];
	selected_prob.x = new boosting_node *[size];

	int index = 0;
	for(int i = 0; i < prob.l; i++) {
		if(prob.y[i] == 1) {
			selected_prob.y[index] = prob.y[i];
			selected_prob.x[index] = prob.x[i];
			index ++;
		}
	}

	for(int i = 0; index < size && i < prob.l; i++) {
		if(prob.y[i] == -1 && d_t[i] > 0) {
			selected_prob.y[index] = prob.y[i];
			selected_prob.x[index] = prob.x[i];
			index ++;
		}
	}

	return true;
}

void equal_resampler::destroy_problem(boosting_problem & prob) {
	// do nothing
}
